package p8selfSort;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.function.FieldScoreQuery;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

/**
 * 自定义排序（设置评分）
 */
public class TestSelfSort {
    public SearchUtils searchUtils;

    @Before
    public void setUp(){
        searchUtils=new SearchUtils();
    }
    /**
     * 索引
     */
    @Test
    public void index(){
         searchUtils=new SearchUtils();
    }

    /**
     * 根据自定义的评分字段进行查询
     */
    @Test
    public void test1() throws IOException {
        Query q=new TermQuery(new Term("content","home"));
        //第一个参数是自定义的评分字段，第二个是字段类型(如果是字符串就是byte类型)
        FieldScoreQuery fsq=new FieldScoreQuery("myScore", FieldScoreQuery.Type.INT);
        //根据，评分域，和原有的query 创建自定意排序查询
        MyCustomerScoreQuery query=new MyCustomerScoreQuery(q,fsq);
        searchUtils.searchSelfSort(query,100);
    }
}
